/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vita.vitasolution.db.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import vita.vitasolution.db.dictionaries.CaseState;

/**
 *
 * @author harker777
 */
@Entity
@Table(name = "`CASE`")
public class Case implements Serializable, EntityWithId {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	@NotNull
	@Size(min = 1, max = 45)
	@Column(name = "Title")
	private String title;
	@NotNull
	@Column(name = "CopiesNumber")
	private Integer copiesNumber;
	@NotNull
	@Column(name = "Fund")
	private Double fund;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "PostDate")
	private Date postDate;
	@ManyToOne
	@JoinColumn(name = "User_ID")
	private User user;
	@Column(name = "CaseState_ID")
	private CaseState caseState;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "aCase")
	private Set<Criterion> criteriaSet;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "aCase")
	private Set<Solution> solutionSet;

	public Case() {
		this.setSolutionSet(new HashSet<Solution>());
		this.setCriteriaSet(new HashSet<Criterion>());
	}

	public Case(Integer id) {
		this();
		this.setId(id);
	}

	public Case(Integer id, String title, Integer copiesNumber, Double fund) {
		this(id);
		this.setTitle(title);
		this.setCopiesNumber(copiesNumber);
		this.setFund(fund);
	}

	@Override
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Integer getCopiesNumber() {
		return copiesNumber;
	}

	public void setCopiesNumber(Integer copiesNumber) {
		this.copiesNumber = copiesNumber;
	}

	public Double getFund() {
		return fund;
	}

	public void setFund(Double fund) {
		this.fund = fund;
	}

	public Date getPostDate() {
		return postDate;
	}

	public void setPostDate(Date postDate) {
		this.postDate = postDate;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public CaseState getCaseState() {
		return caseState;
	}

	public void setCaseState(CaseState caseState) {
		this.caseState = caseState;
	}

	public Set<Criterion> getCriteriaSet() {
		return criteriaSet;
	}

	protected void setCriteriaSet(Set<Criterion> criteriaSet) {
		this.criteriaSet = criteriaSet;
	}

	public void addCriteria(Criterion criteria) {
		criteria.setCase(this);
		this.getCriteriaSet().add(criteria);
	}

	public void removeCriteria(Criterion criteria) {
		this.getCriteriaSet().remove(criteria);
	}

	public Set<Solution> getSolutionSet() {
		return solutionSet;
	}

	protected void setSolutionSet(Set<Solution> solutionSet) {
		this.solutionSet = solutionSet;
	}

	public void addSolution(Solution solution) {
		solution.setCase(this);
		this.getSolutionSet().add(solution);
	}

	public void removeSolution(Solution solution) {
		this.getSolutionSet().remove(solution);
	}

	@Override
	public int hashCode() {
		int hash = 5;
		hash = 23 * hash + (this.id != null ? this.id.hashCode() : 0);
		hash = 23 * hash + (this.title != null ? this.title.hashCode() : 0);
		hash = 23 * hash + (this.copiesNumber != null ? this.copiesNumber.hashCode() : 0);
		hash = 23 * hash + (this.fund != null ? this.fund.hashCode() : 0);
		hash = 23 * hash + (this.postDate != null ? this.postDate.hashCode() : 0);
		hash = 23 * hash + (this.user != null ? this.user.hashCode() : 0);
		hash = 23 * hash + (this.caseState != null ? this.caseState.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Case other = (Case) obj;
		if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
			return false;
		}
		if ((this.title == null) ? (other.title != null) : !this.title.equals(other.title)) {
			return false;
		}
		if (this.copiesNumber != other.copiesNumber && (this.copiesNumber == null || !this.copiesNumber.equals(other.copiesNumber))) {
			return false;
		}
		if (this.fund != other.fund && (this.fund == null || !this.fund.equals(other.fund))) {
			return false;
		}
		if (this.postDate != other.postDate && (this.postDate == null || !this.postDate.equals(other.postDate))) {
			return false;
		}
		if (this.user != other.user && (this.user == null || !this.user.equals(other.user))) {
			return false;
		}
		if (this.caseState != other.caseState) {
			return false;
		}
		return true;
	}
}
